package com.hxzy.controller.front;

import com.hxzy.common.controller.BaseController;
import com.hxzy.common.vo.R;
import com.hxzy.dto.CreateOrderDTO;
import com.hxzy.service.OrdersService;
import com.hxzy.vo.OrdersVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags = "会员订单API")
@RestController
@RequestMapping(value = "/app/order")
public class FrontOrderController extends BaseController {

    @Autowired
    private OrdersService ordersService;

    @ApiOperation(value = "最近一笔订单")
    @GetMapping(value = "/last")
    public R lastOrder(){
        OrdersVO ordersVO = this.ordersService.lastOrder();
        return R.okHasData(ordersVO);
    }

    @ApiOperation(value = "下订单")
    @PostMapping(value = "/submit")
    public R addOrder(@RequestBody @Valid CreateOrderDTO createOrderDTO){

      /*
      参数：
          {remark:this.note,
                payMethod:1,
               addressBookId:this.address.id,
			merchantId: this.merchantId
			}
		原理：
		  1)、判断这些值除remark以外，都不允许为空
		  2)、把购物车中数据写入到订单和订单明细表中
		  3)、删除购物车该用户该商家的信息
       */

        String number=this.ordersService.createOrder(createOrderDTO);
        return R.okHasData(number);
    }
}
